﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using WaterBill.DTO;

namespace WaterBill.DAL
{
    class DAL_Hamlets : clsConnection
    {
        DataTable dtH;

        //Lay danh sach tat ca cac ap
        public DataTable DAL_Hamlets_GetAll(){
            dtH = new DataTable();
            try
            {
                dtH = ExcuteQuery("GetAllHamlet");
            }
            catch
            {              
            }
            return dtH;
        }

        //Lay danh sach cac ap co trang thai bang 1
        public DataTable DAL_Hamlets_GetStatusEnable()
        {
            dtH = new DataTable();
            try
            {
                dtH = ExcuteQuery("GetHamletStatusEnable");
            }
            catch
            {
            }
            return dtH;
        }

        //Them mot ap moi
        public Boolean DAL_Hamlets_Insert(DTO_Hamlets obj)
        {
            try
            {
                AddParameter(new SqlParameter("@Name", obj.Name));
                AddParameter(new SqlParameter("@Status", 1));
                if (ExcuteNonQuery("InsertHamlet"))
                {
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        //Sua ap
        public Boolean DAL_Hamlets_Update(DTO_Hamlets obj)
        {
            try
            {
                AddParameter(new SqlParameter("@HamletId", obj.HamletId));
                AddParameter(new SqlParameter("@Name", obj.Name));
                AddParameter(new SqlParameter("@Status", obj.Status));
                if (ExcuteNonQuery("UpdateHamlet"))
                {
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        //Xoa ap
        public Boolean DAL_Hamlets_Delete(int HamletId)
        {
            try
            {
                AddParameter(new SqlParameter("@HamletId", HamletId));

                if (ExecuteScalar("DeleteHamlet") == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch
            {
            }
            return false;
        }
    }
}
